package cn.hfatec.shms.system.roleMenu.service;

import cn.hfatec.shms.advice.annotation.MysqlDataSource;
import cn.hfatec.shms.system.roleMenu.dao.RoleMenuDao;
import cn.hfatec.shms.system.roleMenu.model.RoleMenu;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;



/**
 *
 * @author hfatec
 * @version 1.0
 *
 * the JAVA code is generate by middlegen
 *
 */
@Service("RoleMenuService")
public class RoleMenuService {

    //注入Dao层
    @Resource(name = "RoleMenuDao")
    private RoleMenuDao roleMenuDao;

    @Transactional
    @MysqlDataSource
    public List queryRoleMenuByRoleId(String roleId) {
        return roleMenuDao.queryRoleMenuByRoleId(roleId);
    }

    @Transactional
    @MysqlDataSource
    public void assignMenu(String roleId, String[] ids) {
        roleMenuDao.deleteRoleMenuBatch(roleId);
        if(ids == null) {
            ids = new String[]{};
        }
        for(String menuId : ids) {
            RoleMenu roleMenu = new RoleMenu();
            roleMenu.setMenuId(menuId);
            roleMenu.setRoleId(roleId);
            roleMenuDao.insert(roleMenu);
        }
    }
}